home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / amigae.june.archive / 000107_crash!kirk.safb.af.mil!BWILLS_Thu, 17 Jun 93 18:06:44 PST.msg < prev    next >
Text File  |  1993-08-31  |  3KB  |  94 lines

  1. Received: by bkhouse.cts.com (V1.16/Amiga)
  2.     id AA00000; Thu, 17 Jun 93 18:06:44 PST
  3. Received: from kirk.safb.af.mil by crash.cts.com with smtp
  4.     (Smail3.1.28.1 #15) id m0o6Sfg-0000p7C; Thu, 17 Jun 93 15:43 PDT
  5. Message-Id: <m0o6Sfg-0000p7C@crash.cts.com>
  6. Date: 17 Jun 93 17:38:00 CST
  7. From: "Barry D. Wills" <BWILLS@kirk.safb.af.mil>
  8. To: "amigae" <amigae@bkhouse.cts.com>
  9. Subject: sscanf.e (fixed)
  10.  
  11. Okay, Son Le.  Here it is.  sscanf() now does exactly what I want it to do.  All
  12. you have to do is write the code to scan the string and place numeric values in
  13. the variables at addresses in the array ssf_var, and put the addresses of
  14. strings there in the same way.  I think the shell should be pretty easy to
  15. work with.  The only thing up in the air is how to implement floats :-)  Oh,
  16. don't forget characters.  I don't know if you want to do octal and hex.  Anyway,
  17. if you don't want to work on the scanning algorithm myself, let me know so I can
  18. stick it on the back burner.  That way it won't get forgotten.  (Oops, back two
  19. sentences should read "yourself" .vs. "myself".  I don't know how to get back to
  20. pervious lines in this mail editor.  It's a massive pain in the BUTT! :(
  21.  
  22. As usual, let me know what you think.
  23.  
  24. -- Barry
  25. DEF ssf_x,
  26.     ssf_var : PTR TO LONG,
  27.     ssf_forCount
  28.  
  29.  
  30. PROC assign ()
  31.   ssf_var [ssf_forCount] := ssf_x
  32.   INC ssf_forCount
  33. ENDPROC
  34.  
  35.  
  36. PROC sscanf (str, fmt, varList)
  37.   DEF numRead = 0, i, listLen, var = NIL
  38.  
  39.   /* Get/set length of list. */
  40.   listLen := ListLen (varList)
  41.   SetList (varList, listLen)
  42.  
  43.   /* Extract addresses from list. */
  44.   ssf_var := New (listLen * 4)  /* 4=SIZEOF LONG. */
  45.   ssf_forCount := 0
  46.   ForAll ({ssf_x}, varList, `assign ())
  47.  
  48. /*------------------------------------------------------------------------*/
  49. /* Just some displays to see what we got as params.                       */
  50. /* This is where your code goes to parse the string.                      */
  51.  
  52.   WriteF ('Values passed to sscanf():\n')
  53.   WriteF ('  ListLen(varList)=\d\n', listLen)
  54.   WriteF ('  string=\s\n' +
  55.           '  format=\s\n', str, fmt)
  56.  
  57.   FOR i := 0 TO (listLen - 1)
  58.     var := ssf_var [i]  /* get the address from the array. */
  59.     WriteF ('  ssf_var[\d]=\d\n', i, ^var)
  60.     ^var := ^var + 20  /* change the values just to see the results. */
  61.   ENDFOR
  62.  
  63.   ^var := 'Pretend this is an extracted string.'
  64.     /* simulate extracting a string.  look at end of main to see result. */
  65.  
  66. /* End of displays.                                                       */
  67. /*------------------------------------------------------------------------*/
  68.  
  69.   Dispose (ssf_var)
  70. ENDPROC  numRead
  71.  
  72.  
  73.  
  74. PROC main ()
  75.   DEF string [20] : STRING,
  76.       format [20] : STRING,
  77.       a=90, b=91, c=92, d=93,
  78.       numRead
  79.  
  80.   StrCopy (string, '100 101 102 103', ALL)
  81.   StrCopy (format, '\d \d \d \d', ALL)
  82.   /* ---> OR...
  83.     StrCopy (format, '%d %d %d %d', ALL)
  84.   */
  85.  
  86.   numRead := sscanf (string, format, [{a},{b},{c},{d}])
  87.  
  88.   WriteF ('The modified values:\n' +
  89.           '  a=\d\n' +
  90.           '  b=\d\n' +
  91.           '  c=\d\n' +
  92.           '  d=\d (address of a string)\n', a, b, c, d)
  93.   WriteF ('  string at d=\s\n', d)
  94. ENDPROC